<template>
  <div class="home">
    <h1>欢迎使用漫画创作助手</h1>
    <div class="feature-cards">
      <router-link
        v-for="feature in features"
        :key="feature.path"
        :to="{ name: feature.path }"
        class="feature-card">
        <div class="card-icon">
          <i :class="feature.icon"></i>
        </div>
        <h3>{{ feature.title }}</h3>
        <p>{{ feature.description }}</p>
      </router-link>
    </div>

    <div v-if="recentHistory.length > 0" class="history-section">
      <h2>最近创作</h2>
      <div class="history-items">
        <div v-for="item in recentHistory" :key="item.timestamp" class="history-item">
          <div class="item-type">{{ getTypeLabel(item.type) }}</div>
          <div class="item-content">{{ truncateContent(item.content) }}</div>
          <div class="item-time">{{ formatTime(item.timestamp) }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  name: 'Home',
  data() {
    return {
      features: [
        {
          path: 'text',
          title: '文本转漫画',
          description: '通过文字描述生成漫画',
          icon: 'fas fa-font'
        },
        {
          path: 'image',
          title: '图像转漫画',
          description: '将照片转换为漫画风格',
          icon: 'fas fa-image'
        },
        {
          path: 'style',
          title: '风格定制',
          description: '创建个性化漫画风格',
          icon: 'fas fa-palette'
        },
        {
          path: 'story',
          title: '故事生成',
          description: '自动生成漫画剧情',
          icon: 'fas fa-book'
        }
      ]
    }
  },
  computed: {
    ...mapGetters(['recentHistory'])
  },
  methods: {
    getTypeLabel(type) {
      const labels = {
        text: '文本漫画',
        image: '图像转换',
        story: '故事生成'
      }
      return labels[type] || type
    },
    truncateContent(content) {
      if (content.length > 50) {
        return content.substring(0, 50) + '...'
      }
      return content
    },
    formatTime(timestamp) {
      return new Date(timestamp).toLocaleString()
    }
  }
}
</script>

<style scoped>

.home {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

h1 {
  text-align: center;
  margin-bottom: 30px;
  color: #333;
}

.feature-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
}

.feature-card {
  background-color: white;
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  text-decoration: none;
  color: #333;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s, box-shadow 0.3s;
}

.feature-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.card-icon {
  font-size: 2.5rem;
  color: #4CAF50;
  margin-bottom: 15px;
}

.feature-card h3 {
  margin-bottom: 10px;
}

.feature-card p {
  color: #666;
}

.history-section {
  margin-top: 40px;
}

.history-section h2 {
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.history-items {
  display: grid;
  gap: 15px;
}

.history-item {
  background-color: white;
  border-radius: 8px;
  padding: 15px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  display: grid;
  grid-template-columns: 100px 1fr 150px;
  align-items: center;
}

.item-type {
  font-weight: bold;
  color: #4CAF50;
}

.item-content {
  color: #666;
  padding: 0 15px;
}

.item-time {
  text-align: right;
  font-size: 0.9em;
  color: #999;
}

@media (max-width: 768px) {
  .feature-cards {
    grid-template-columns: 1fr 1fr;
  }

  .history-item {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .item-time {
    text-align: left;
  }
}

@media (max-width: 480px) {
  .feature-cards {
    grid-template-columns: 1fr;
  }
}
</style>